package com.bdzl.admin.controller.sys;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdzl.pub.entity.sys.OrgFddcaDO;
import com.bdzl.admin.service.sys.OrgFddcaService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * -机构与法大大企业 CA 证书关系表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:59:22
 */
 
@Controller
@RequestMapping("/bdzl/orgFddca")
public class OrgFddcaController extends BaseController {
	@Autowired
	private OrgFddcaService orgFddcaService;
	
	@GetMapping()
	String OrgFddca(){
	    return "bdzl/orgFddca/orgFddca";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrgFddcaDO> orgFddcaList = orgFddcaService.list(query);
		int total = orgFddcaService.count(query);
		PageUtils pageUtils = new PageUtils(orgFddcaList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/orgFddca/add";
	}

	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Integer id,Model model){
		OrgFddcaDO orgFddca = orgFddcaService.get(id);
		model.addAttribute("orgFddca", orgFddca);
	    return "bdzl/orgFddca/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OrgFddcaDO orgFddca){
		if(orgFddcaService.save(orgFddca)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OrgFddcaDO orgFddca){
		orgFddcaService.update(orgFddca);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer id){
		if(orgFddcaService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] ids){
		orgFddcaService.batchRemove(ids);
		return R.ok();
	}
	
}
